class ComicChapterModel {
  final int? status;
  final int? comicType;
  final String? title;
  final int? type;
  final int? mediaType;
  final String? url; // 图片或视频地址，如果有多个用,号分割
  final int? price;
  final int? clickNum;
  final String? countryCode;
  final String? comicId;
  final String? desc;
  final int? chapterNum;
  final String? id;
  final String? key;

  ComicChapterModel({
    this.status,
    this.comicType,
    this.title,
    this.type,
    this.mediaType,
    this.url,
    this.price,
    this.clickNum,
    this.countryCode,
    this.comicId,
    this.desc,
    this.chapterNum,
    this.id,
    this.key,
  });

  factory ComicChapterModel.fromJson(Map<String, dynamic> json) {
    print('Parsing chapter data: $json'); // 添加调试信息
    return ComicChapterModel(
      status: json['status']?.toInt(),
      comicType: json['comicType']?.toInt(),
      title: json['title']?.toString(),
      type: json['type']?.toInt(),
      mediaType: json['mediaType']?.toInt(),
      url: json['url']?.toString(),
      price: json['price']?.toInt(),
      clickNum: json['clickNum']?.toInt(),
      countryCode: json['countryCode']?.toString(),
      comicId: json['comicId']?.toString(),
      desc: json['desc']?.toString(),
      chapterNum: json['chapterNum']?.toInt(),
      id: json['id']?.toString(),
      key: json['key']?.toString(),
    );
  }

  // 解析URL字符串为图片列表
  List<String> get imageUrls {
    print('Raw URL data: $url'); // 添加调试信息
    if (url == null || url!.isEmpty) return [];

    return url!
        .split(',')
        .map((e) => e.trim())
        .where((e) => e.isNotEmpty)
        .toList();
  }

  Map<String, dynamic> toJson() {
    return {
      'status': status,
      'comicType': comicType,
      'title': title,
      'type': type,
      'mediaType': mediaType,
      'url': url,
      'price': price,
      'clickNum': clickNum,
      'countryCode': countryCode,
      'comicId': comicId,
      'desc': desc,
      'chapterNum': chapterNum,
      'id': id,
      'key': key,
    };
  }
}
